<?php
namespace backend\controllers;

use Yii;
use yii\web\Controller;
use common\collection\Common;
use common\collection\BackendCommon;
use common\helpers\PublicFun;
use backend\config\routeParams;


/**
 * Site controller
 */
class SceneactiveController extends Controller
{

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    public  function beforeAction($action){
        if(BackendCommon::init()){
            if(BackendCommon::rbac()){
                return true;
            }else{
                Yii::$app->response->redirect( ['site/error']);
            }
        }else{
            Yii::$app->response->redirect( ['login/index']);
        }
    }
    //首页
    public function actionIndex()
    {
        if(Yii::$app->request->get()){
           $dataget = Yii::$app->request->get();
           $dataget = Common::ArrayFilter($dataget);
           // print_r($dataget);exit;
           $cookies = Yii::$app->request->cookies;
           $admin = $cookies->get('MytipIdBack')->value;
           $dataget['MytipId'] = $admin;
           $dataget['PageNo'] = $dataget['page'];
           $dataget['PageSize'] = 12;
           // 100 模板 200  我的
           if($dataget['type'] == 100){
                $route = 'TemplateGetList';

           }else{
                $route = 'ActRoomGetList';
           }
           $url = routeParams::HttpUrl($route);
           $result = PublicFun::PostPackage($dataget, $url);
           $result = json_decode($result['Body'],true);
           if($result['TotalCount'] == 0 || count($result['Models']) <= 0){
              $result['TotalCount'] = 1;
              $result['Models'] = ['暂无数据'];
           }
           $ret = [
            'total' => $result['TotalCount'],
            'rows' => $result['Models'],
            'page' => $dataget['page'],
           ];
           die(json_encode($ret));
        }
        return $this->render('index');
    }
    // 活动详情
    public function actionDetial()
    {
        return $this->render('detial');
    }
    // 创建模板
    public function actionCreate()
    {
        return $this->render('create');
    }
    // 添加活动
    public function actionAddActive()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       $url = routeParams::HttpUrl('ActTemplateCreate');
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
        // print_r($result);exit;
       die(json_encode($result));
    }
    // // 
    // public function actionGetDetial()
    // {
    //    $datapost = Yii::$app->request->post();
    //    $datapost = Common::ArrayFilter($datapost);
    //    $url = routeParams::HttpUrl('ActDetail');
    //    $result = PublicFun::PostPackage($datapost, $url);
    //    $result = json_decode($result['Body'],true);
    //    die(json_encode($result));
    // }
     // 添加活动
    public function actionGetList()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       $url = routeParams::HttpUrl('ActApplyList');
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
       $ret = [
        'PageNo' => $datapost['PageNo'], 
        'PageSize' => $datapost["PageSize"],
        'total' => $result["TotalCount"],
        'data' => $result['Models']
       ];
       die(json_encode($ret));
    }
    // 创建房间
    public function actionMakeRoom()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       $url = routeParams::HttpUrl('RoomCreate');
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
        // print_r($result);exit;
       die(json_encode($result));
    }
    // 获取模板详情
    public function actionModelDetial()
    {
       $datapost = Yii::$app->request->post();
       $datapost = Common::ArrayFilter($datapost);
       $cookies = Yii::$app->request->cookies;
       $admin = $cookies->get('MytipIdBack')->value;
       $datapost['MytipId'] = $admin;
       $url = routeParams::HttpUrl('ActTemplateDetail');
       $result = PublicFun::PostPackage($datapost, $url);
       $result = json_decode($result['Body'],true);
       die(json_encode($result));
    }
    
   
  

}
